package com.practice.J2E.Test;

import com.practice.J2E.invoke.Permission;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * @author kayn
 * @create 2023-10-07 下午 02:13
 */
public class InvokeTest {

    public static void main(String[] args) throws Exception {

        Permission permission = new Permission("影","Ei", "雷电将军","稻妻") {

            @Override
            public void E() {
                System.out.println("神变恶曜开眼");
            }

            @Override
            public void Q() {
                System.out.println("奥义梦想真说");
            }
        };

        testField(permission);

        testMethod(permission);

    }

    private static void testMethod(Permission ei)  throws Exception {

        Class<Permission> permissionClass = Permission.class;

        Method Q = permissionClass.getMethod("Q");

        Q.invoke(ei);

        Method E = permissionClass.getMethod("E");

        E.invoke(ei);

    }

    private static void testField(Permission ei) throws Exception {

        Class<Permission> permissionClass = Permission.class;

        Field field = permissionClass.getDeclaredField("name");

        field.setAccessible(true);

        //字段值
        System.out.println(field.get(ei));

        //字段作用域
        int modifiers = field.getModifiers();

        System.out.println(modifiers);

        System.out.println(Modifier.isPrivate(modifiers));

    }

}
